/*
 * HomeBudgetView.java
 */
package homebudget;

import java.awt.Font;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.UnsupportedLookAndFeelException;
import org.jdesktop.application.Action;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import org.jvnet.substance.skin.SubstanceOfficeSilver2007LookAndFeel;
import porownaniecen.*;
import receiptReaderTool.checkReceipt;
import receiptReaderTool.receiptReaderTool;
import treningImageTools.manageProfilesFrame;
import treningImageTools.treningImageToolsFrame;
/**
 * The application's main frame.
 */
public class HomeBudgetView extends FrameView {

    public DataBase db = null;


   

    public HomeBudgetView(SingleFrameApplication app) {
        super(app);
         
        //TODO - tutaj porzadek:p
        try {
            UIManager.setLookAndFeel(new SubstanceOfficeSilver2007LookAndFeel());
//        } catch (ClassNotFoundException ex) {
//            Logger.getLogger(HomeBudgetView.class.getName()).log(Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            Logger.getLogger(HomeBudgetView.class.getName()).log(Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            Logger.getLogger(HomeBudgetView.class.getName()).log(Level.SEVERE, null, ex);
//        } catch (UnsupportedLookAndFeelException ex) {
//            Logger.getLogger(HomeBudgetView.class.getName()).log(Level.SEVERE, null, ex);
//        }
          } catch (Exception ex) {
            
          }
        db = new DataBase();

      initComponents();      

        //to bedzie mozna usunac
        expensesList.setListData(db.getExpensesArray());
        contributionsList.setListData(db.getContributionsArray());

        //wstęne ustawienia dla jTable z porówaniem
        DataBaseMySql baza = new DataBaseMySql(HomeBudgetApp.getConnectionString());
        jComboBoxKategoria.setModel(new DefaultComboBoxModel(baza.listaKategoriaProdukt().toArray()));
        baza.close();
        jTablePorownanie.setVisible(false);
        jTablePorownanie.setAutoCreateRowSorter(true);
        jTablePorownanie.setFont(new Font("Arial", Font.BOLD, 12));
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = HomeBudgetApp.getApplication().getMainFrame();
            aboutBox = new HomeBudgetAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        HomeBudgetApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        differentViews = new javax.swing.JTabbedPane();
        tabs = new javax.swing.JPanel();
        expensesAndContributions = new javax.swing.JTabbedPane();
        expensesPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        expensesList = new javax.swing.JList();
        contributionsPanel = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        contributionsList = new javax.swing.JList();
        manualEntry = new javax.swing.JButton();
        fromReceipt = new javax.swing.JButton();
        fromScan = new javax.swing.JButton();
        deleteEntryButton = new javax.swing.JButton();
        reports = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        monthsList = new javax.swing.JList();
        showReportButton = new javax.swing.JButton();
        diagrams = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        monthsDiagramsList = new javax.swing.JList();
        createBarDiagram = new javax.swing.JButton();
        createCircleDiagram = new javax.swing.JButton();
        diagramComboBox = new javax.swing.JComboBox();
        comparisions = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jComboBoxKategoria = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jComboBoxProdukt = new javax.swing.JComboBox();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTablePorownanie = new javax.swing.JTable();
        jLabel4 = new javax.swing.JLabel();
        jButtonWyswietl = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        categoryMenu = new javax.swing.JMenu();
        editCategoriesItem = new javax.swing.JMenuItem();
        shopsMenu = new javax.swing.JMenu();
        editShopsItem = new javax.swing.JMenuItem();
        receiptMenu = new javax.swing.JMenu();
        readReceiptItem = new javax.swing.JMenuItem();
        receiptToolsMenu = new javax.swing.JMenu();
        checkReceiptToolItem = new javax.swing.JMenuItem();
        manageProfilesToolItem = new javax.swing.JMenuItem();
        trenningImagesToolItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();

        mainPanel.setName("mainPanel"); // NOI18N

        differentViews.setName("differentViews"); // NOI18N
        differentViews.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                differentViewsStateChanged(evt);
            }
        });

        tabs.setName("tabs"); // NOI18N

        expensesAndContributions.setName("expensesAndContributions"); // NOI18N
        expensesAndContributions.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                expensesAndContributionsStateChanged(evt);
            }
        });

        expensesPanel.setName("expensesPanel"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        expensesList.setModel(new javax.swing.AbstractListModel() {
            public LinkedList<Entry> entries = db.expenses;

            public int getSize() { return entries.size(); }
            public Object getElementAt(int i) { return entries.get(i); }
        });
        expensesList.setName("expensesList"); // NOI18N
        expensesList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                expensesListValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(expensesList);

        javax.swing.GroupLayout expensesPanelLayout = new javax.swing.GroupLayout(expensesPanel);
        expensesPanel.setLayout(expensesPanelLayout);
        expensesPanelLayout.setHorizontalGroup(
            expensesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE)
        );
        expensesPanelLayout.setVerticalGroup(
            expensesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
        );

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(homebudget.HomeBudgetApp.class).getContext().getResourceMap(HomeBudgetView.class);
        expensesAndContributions.addTab(resourceMap.getString("expensesPanel.TabConstraints.tabTitle"), expensesPanel); // NOI18N

        contributionsPanel.setName("contributionsPanel"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        contributionsList.setModel(new javax.swing.AbstractListModel() {
            public LinkedList<Entry> entries = db.contributions;

            public int getSize() { return entries.size(); }
            public Object getElementAt(int i) { return entries.get(i); }
        });
        contributionsList.setName("contributionsList"); // NOI18N
        contributionsList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                contributionsListValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(contributionsList);

        javax.swing.GroupLayout contributionsPanelLayout = new javax.swing.GroupLayout(contributionsPanel);
        contributionsPanel.setLayout(contributionsPanelLayout);
        contributionsPanelLayout.setHorizontalGroup(
            contributionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE)
        );
        contributionsPanelLayout.setVerticalGroup(
            contributionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
        );

        expensesAndContributions.addTab(resourceMap.getString("contributionsPanel.TabConstraints.tabTitle"), contributionsPanel); // NOI18N

        manualEntry.setText(resourceMap.getString("manualEntry.text")); // NOI18N
        manualEntry.setName("manualEntry"); // NOI18N
        manualEntry.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                manualEntryActionPerformed(evt);
            }
        });

        fromReceipt.setText(resourceMap.getString("fromReceipt.text")); // NOI18N
        fromReceipt.setName("fromReceipt"); // NOI18N
        fromReceipt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fromReceiptActionPerformed(evt);
            }
        });

        fromScan.setText(resourceMap.getString("fromScan.text")); // NOI18N
        fromScan.setName("fromScan"); // NOI18N
        fromScan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fromScanActionPerformed(evt);
            }
        });

        deleteEntryButton.setText(resourceMap.getString("deleteEntryButton.text")); // NOI18N
        deleteEntryButton.setName("deleteEntryButton"); // NOI18N
        deleteEntryButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteEntryButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout tabsLayout = new javax.swing.GroupLayout(tabs);
        tabs.setLayout(tabsLayout);
        tabsLayout.setHorizontalGroup(
            tabsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabsLayout.createSequentialGroup()
                .addComponent(expensesAndContributions, javax.swing.GroupLayout.DEFAULT_SIZE, 367, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(fromScan, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
                    .addComponent(fromReceipt, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
                    .addComponent(manualEntry, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(deleteEntryButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        tabsLayout.setVerticalGroup(
            tabsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(manualEntry)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(fromReceipt)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(fromScan)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(deleteEntryButton)
                .addContainerGap(184, Short.MAX_VALUE))
            .addComponent(expensesAndContributions)
        );

        differentViews.addTab(resourceMap.getString("tabs.TabConstraints.tabTitle"), tabs); // NOI18N

        reports.setName("reports"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        monthsList.setName("monthsList"); // NOI18N
        jScrollPane3.setViewportView(monthsList);

        showReportButton.setText(resourceMap.getString("showReportButton.text")); // NOI18N
        showReportButton.setName("showReportButton"); // NOI18N
        showReportButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showReportButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout reportsLayout = new javax.swing.GroupLayout(reports);
        reports.setLayout(reportsLayout);
        reportsLayout.setHorizontalGroup(
            reportsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, reportsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 351, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(showReportButton, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        reportsLayout.setVerticalGroup(
            reportsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(reportsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(reportsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(showReportButton)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 283, Short.MAX_VALUE))
                .addContainerGap())
        );

        differentViews.addTab(resourceMap.getString("reports.TabConstraints.tabTitle"), reports); // NOI18N

        diagrams.setName("diagrams"); // NOI18N

        jScrollPane5.setName("jScrollPane5"); // NOI18N

        monthsDiagramsList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        monthsDiagramsList.setName("monthsDiagramsList"); // NOI18N
        jScrollPane5.setViewportView(monthsDiagramsList);

        createBarDiagram.setText(resourceMap.getString("createBarDiagram.text")); // NOI18N
        createBarDiagram.setName("createBarDiagram"); // NOI18N
        createBarDiagram.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createBarDiagramActionPerformed(evt);
            }
        });

        createCircleDiagram.setText(resourceMap.getString("createCircleDiagram.text")); // NOI18N
        createCircleDiagram.setName("createCircleDiagram"); // NOI18N
        createCircleDiagram.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createCircleDiagramActionPerformed(evt);
            }
        });

        diagramComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Wydatki", "Zarobki" }));
        diagramComboBox.setName("diagramComboBox"); // NOI18N

        javax.swing.GroupLayout diagramsLayout = new javax.swing.GroupLayout(diagrams);
        diagrams.setLayout(diagramsLayout);
        diagramsLayout.setHorizontalGroup(
            diagramsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(diagramsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(diagramsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(createBarDiagram)
                    .addComponent(createCircleDiagram)
                    .addComponent(diagramComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(37, 37, 37))
        );
        diagramsLayout.setVerticalGroup(
            diagramsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(diagramsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(diagramsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(diagramsLayout.createSequentialGroup()
                        .addComponent(createBarDiagram)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(createCircleDiagram)
                        .addGap(18, 18, 18)
                        .addComponent(diagramComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(diagramsLayout.createSequentialGroup()
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 269, Short.MAX_VALUE)
                        .addGap(25, 25, 25))))
        );

        differentViews.addTab(resourceMap.getString("diagrams.TabConstraints.tabTitle"), diagrams); // NOI18N

        comparisions.setName("comparisions"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jComboBoxKategoria.setName("jComboBoxKategoria"); // NOI18N
        jComboBoxKategoria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxKategoriaActionPerformed(evt);
            }
        });

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jComboBoxProdukt.setModel(new javax.swing.DefaultComboBoxModel(new String[] { ""}));
        jComboBoxProdukt.setName("jComboBoxProdukt"); // NOI18N
        jComboBoxProdukt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxProduktActionPerformed(evt);
            }
        });

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        jTablePorownanie.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTablePorownanie.setName("jTablePorownanie"); // NOI18N
        jScrollPane4.setViewportView(jTablePorownanie);

        jLabel4.setFont(resourceMap.getFont("jLabelInfo.font")); // NOI18N
        jLabel4.setForeground(resourceMap.getColor("jLabelInfo.foreground")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabelInfo.text")); // NOI18N
        jLabel4.setName("jLabelInfo"); // NOI18N

        jButtonWyswietl.setText(resourceMap.getString("jButtonWyswietl.text")); // NOI18N
        jButtonWyswietl.setName("jButtonWyswietl"); // NOI18N
        jButtonWyswietl.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonWyswietlActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout comparisionsLayout = new javax.swing.GroupLayout(comparisions);
        comparisions.setLayout(comparisionsLayout);
        comparisionsLayout.setHorizontalGroup(
            comparisionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(comparisionsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(comparisionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(comparisionsLayout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxKategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxProdukt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButtonWyswietl))
                    .addComponent(jLabel4)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 468, Short.MAX_VALUE))
                .addContainerGap())
        );
        comparisionsLayout.setVerticalGroup(
            comparisionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(comparisionsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(comparisionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jComboBoxKategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jComboBoxProdukt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonWyswietl))
                .addGap(5, 5, 5)
                .addComponent(jLabel4)
                .addGap(11, 11, 11)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE))
        );

        differentViews.addTab(resourceMap.getString("comparisions.TabConstraints.tabTitle"), comparisions); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(differentViews, javax.swing.GroupLayout.DEFAULT_SIZE, 493, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(differentViews, javax.swing.GroupLayout.DEFAULT_SIZE, 333, Short.MAX_VALUE)
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        fileMenu.add(jMenuItem1);

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setText(resourceMap.getString("jMenuItem2.text")); // NOI18N
        jMenuItem2.setName("jMenuItem2"); // NOI18N
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        fileMenu.add(jMenuItem2);

        jSeparator1.setName("jSeparator1"); // NOI18N
        fileMenu.add(jSeparator1);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(homebudget.HomeBudgetApp.class).getContext().getActionMap(HomeBudgetView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        categoryMenu.setText(resourceMap.getString("categoryMenu.text")); // NOI18N
        categoryMenu.setName("categoryMenu"); // NOI18N

        editCategoriesItem.setText(resourceMap.getString("editCategoriesItem.text")); // NOI18N
        editCategoriesItem.setName("editCategoriesItem"); // NOI18N
        editCategoriesItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editCategoriesItemActionPerformed(evt);
            }
        });
        categoryMenu.add(editCategoriesItem);

        menuBar.add(categoryMenu);

        shopsMenu.setText(resourceMap.getString("shopsMenu.text")); // NOI18N
        shopsMenu.setName("shopsMenu"); // NOI18N

        editShopsItem.setText(resourceMap.getString("editShopsItem.text")); // NOI18N
        editShopsItem.setName("editShopsItem"); // NOI18N
        editShopsItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editShopsItemActionPerformed(evt);
            }
        });
        shopsMenu.add(editShopsItem);

        menuBar.add(shopsMenu);

        receiptMenu.setText(resourceMap.getString("receiptMenu.text")); // NOI18N
        receiptMenu.setName("receiptMenu"); // NOI18N

        readReceiptItem.setText(resourceMap.getString("readReceiptItem.text")); // NOI18N
        readReceiptItem.setName("readReceiptItem"); // NOI18N
        readReceiptItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                readReceiptItemActionPerformed(evt);
            }
        });
        receiptMenu.add(readReceiptItem);

        receiptToolsMenu.setText(resourceMap.getString("receiptToolsMenu.text")); // NOI18N
        receiptToolsMenu.setName("receiptToolsMenu"); // NOI18N

        checkReceiptToolItem.setText(resourceMap.getString("checkReceiptToolItem.text")); // NOI18N
        checkReceiptToolItem.setName("checkReceiptToolItem"); // NOI18N
        checkReceiptToolItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkReceiptToolItemActionPerformed(evt);
            }
        });
        receiptToolsMenu.add(checkReceiptToolItem);

        manageProfilesToolItem.setText(resourceMap.getString("manageProfilesToolItem.text")); // NOI18N
        manageProfilesToolItem.setName("manageProfilesToolItem"); // NOI18N
        manageProfilesToolItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                manageProfilesToolItemActionPerformed(evt);
            }
        });
        receiptToolsMenu.add(manageProfilesToolItem);

        trenningImagesToolItem.setText(resourceMap.getString("trenningImagesToolItem.text")); // NOI18N
        trenningImagesToolItem.setName("trenningImagesToolItem"); // NOI18N
        trenningImagesToolItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                trenningImagesToolItemActionPerformed(evt);
            }
        });
        receiptToolsMenu.add(trenningImagesToolItem);

        receiptMenu.add(receiptToolsMenu);

        menuBar.add(receiptMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setText(resourceMap.getString("aboutMenuItem.text")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setComponent(mainPanel);
        setMenuBar(menuBar);
    }// </editor-fold>//GEN-END:initComponents

    private void manualEntryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_manualEntryActionPerformed
        manualEntryDialog newEntry = new manualEntryDialog(this.getFrame(), true);
        newEntry.setDataBase(this.db);
       // newEntry.setCategoriesDB(this.catDB);
        //newEntry.setShopsDB(this.shopsDB);
        newEntry.setVisible(true);

        if (!newEntry.isCanceled) {
            expensesList.setListData(db.getExpensesArray());
            contributionsList.setListData(db.getContributionsArray());
        }

    }//GEN-LAST:event_manualEntryActionPerformed

    private void fromReceiptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fromReceiptActionPerformed
        receiptReaderTool();
         expensesList.setListData(db.getExpensesArray());
         contributionsList.setListData(db.getContributionsArray());
    }//GEN-LAST:event_fromReceiptActionPerformed

    private void fromScanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fromScanActionPerformed
       PlikBankowyDialog wyciag = new PlikBankowyDialog(this.getFrame(),true);
       wyciag.setVisible(true);

       expensesList.setListData(db.getExpensesArray());
       contributionsList.setListData(db.getContributionsArray());

    }//GEN-LAST:event_fromScanActionPerformed

    private void deleteEntryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteEntryButtonActionPerformed
        switch (expensesAndContributions.getSelectedIndex()) {
            case 0:
                if (expensesList.getSelectedIndex() != -1) {
                    db.expenses.remove(expensesList.getSelectedIndex());
                    expensesList.setListData(db.getExpensesArray());
                }
                break;
            case 1:
                if (contributionsList.getSelectedIndex() != -1) {
                    db.contributions.remove(contributionsList.getSelectedIndex());
                    contributionsList.setListData(db.getContributionsArray());
                }
                break;
        }
        deleteEntryButton.setVisible(false);
    }//GEN-LAST:event_deleteEntryButtonActionPerformed

    private void expensesListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_expensesListValueChanged
        if (expensesList.getSelectedIndex() != -1) {
            deleteEntryButton.setVisible(true);
        }
    }//GEN-LAST:event_expensesListValueChanged

    private void contributionsListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_contributionsListValueChanged
        if (contributionsList.getSelectedIndex() != -1) {
            deleteEntryButton.setVisible(true);
        }
    }//GEN-LAST:event_contributionsListValueChanged

    private void expensesAndContributionsStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_expensesAndContributionsStateChanged

        switch (expensesAndContributions.getSelectedIndex()) {
            case 0:
                if (expensesList.getSelectedIndex() == -1) {
                    deleteEntryButton.setVisible(false);
                } else {
                    deleteEntryButton.setVisible(true);
                }
                expensesList.setListData(db.getExpensesArray());
                break;
            case 1:
                if (contributionsList.getSelectedIndex() == -1) {
                    deleteEntryButton.setVisible(false);
                } else {
                    deleteEntryButton.setVisible(true);
                }
                contributionsList.setListData(db.getContributionsArray());
                break;
        }
    }//GEN-LAST:event_expensesAndContributionsStateChanged

    private void editCategoriesItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editCategoriesItemActionPerformed
        CategoriesDialog dialog = new CategoriesDialog(this.getFrame(), true);      
        dialog.setVisible(true);
        DataBaseMySql db = new DataBaseMySql(HomeBudgetApp.getConnectionString());
        jComboBoxKategoria.setModel(new DefaultComboBoxModel(db.listaKategoriaProdukt().toArray()));
        db.close();
    }//GEN-LAST:event_editCategoriesItemActionPerformed

    private void editShopsItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editShopsItemActionPerformed
        ShopsDialog dialog = new ShopsDialog(this.getFrame(), true);      
        dialog.setVisible(true);
    }//GEN-LAST:event_editShopsItemActionPerformed

    private void showReportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showReportButtonActionPerformed
        String date = monthsList.getSelectedValue().toString();
        System.out.println(date);
        Report report = new Report(date, db);

        ReportDialog reportdialog = new ReportDialog(this.getFrame(), false);
        reportdialog.setReport(report);
        reportdialog.setVisible(true);
    }//GEN-LAST:event_showReportButtonActionPerformed

    private void differentViewsStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_differentViewsStateChanged
         if (differentViews.getSelectedIndex() == 1) {
            LinkedList<String> months = new LinkedList<String>();
            SimpleDateFormat sdf = new SimpleDateFormat("MMM,''yy");
            for (Entry e : db.expenses) {
                String d = sdf.format(e.date);
                //System.out.println(d);
                if (!months.contains(d)) {
                    months.add(d);
                }
            }

            monthsList.setListData(months.toArray());
<<<<<<< .mine
        } else if (differentViews.getSelectedIndex() == 2) {
            LinkedList<String> months = new LinkedList<String>();
            SimpleDateFormat sdf = new SimpleDateFormat("MMM,''yy");
            for (Entry e : db.expenses) {
                String d = sdf.format(e.date);
                //System.out.println(d);
                if (!months.contains(d)) {
                    months.add(d);
                }
            }

            monthsDiagramsList.setListData(months.toArray());
         } else if (differentViews.getSelectedIndex() == 3) {
             DataBaseMySql db = new DataBaseMySql(HomeBudgetApp.getConnectionString());
             jComboBoxKategoria.setModel(new DefaultComboBoxModel(db.listaKategoriaProdukt().toArray()));
             db.close();
         }

=======
        } else if (differentViews.getSelectedIndex() == 2) {
            LinkedList<String> months = new LinkedList<String>();
            SimpleDateFormat sdf = new SimpleDateFormat("MMM,''yy");
            for (Entry e : db.expenses) {
                String d = sdf.format(e.date);
                //System.out.println(d);
                if (!months.contains(d)) {
                    months.add(d);
                }
            }

            monthsDiagramsList.setListData(months.toArray());
        }
>>>>>>> .r12
    }//GEN-LAST:event_differentViewsStateChanged

    private void jComboBoxProduktActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxProduktActionPerformed
        // TODO add your handling code here:

    }//GEN-LAST:event_jComboBoxProduktActionPerformed

    private void jComboBoxKategoriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxKategoriaActionPerformed
        JComboBox jcb = (JComboBox)evt.getSource();
        String nazwaKategori = (String)jcb.getSelectedItem();

        DataBaseMySql db = new DataBaseMySql(HomeBudgetApp.getConnectionString());        
        LinkedList<String> tmp = db.listaProdukt(nazwaKategori,HomeBudgetApp.getIdbudzetu());

        ComboBoxModel model = new DefaultComboBoxModel(tmp.toArray());
        jComboBoxProdukt.setModel(model);

        db.close();
    }//GEN-LAST:event_jComboBoxKategoriaActionPerformed

    private void jButtonWyswietlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonWyswietlActionPerformed
        String nazwaKategorii = (String)jComboBoxKategoria.getSelectedItem();
        String nazwaProduktu = (String)jComboBoxProdukt.getSelectedItem();

        jLabel4.setText("Porownanie dla "+nazwaProduktu+" z kategorii "+nazwaKategorii);        

        jTablePorownanie.setVisible(true);
        DataBaseMySql db = new DataBaseMySql(HomeBudgetApp.getConnectionString());
        TableModel tmodel = new PorownajCeny(db.getConnection(),nazwaProduktu,nazwaKategorii);

        //ustawieni sortowania
        RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tmodel);
        jTablePorownanie.setRowSorter(sorter);

        jTablePorownanie.setModel(tmodel);

       db.close();
    }//GEN-LAST:event_jButtonWyswietlActionPerformed

    private void receiptReaderTool(){
        /* TODO
         * Potrzebne dane:
         * - ID budzetu
         */
        int budgetID = 1;
        receiptReaderTool scannerFrame = new receiptReaderTool(budgetID);
        scannerFrame.setVisible(true);
    }
    
    private void readReceiptItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_readReceiptItemActionPerformed
        receiptReaderTool();
    }//GEN-LAST:event_readReceiptItemActionPerformed

    private void checkReceiptToolItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkReceiptToolItemActionPerformed
        checkReceipt receiptcheck = new checkReceipt();
        receiptcheck.setVisible(true);
    }//GEN-LAST:event_checkReceiptToolItemActionPerformed

    private void trenningImagesToolItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_trenningImagesToolItemActionPerformed
        treningImageToolsFrame treningFrame = new treningImageToolsFrame();
        treningFrame.setVisible(true);
    }//GEN-LAST:event_trenningImagesToolItemActionPerformed

    private void manageProfilesToolItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_manageProfilesToolItemActionPerformed
        manageProfilesFrame profilesFrame = new manageProfilesFrame();
        profilesFrame.setVisible(true);
    }//GEN-LAST:event_manageProfilesToolItemActionPerformed

    private void createBarDiagramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createBarDiagramActionPerformed
        // TODO add your handling code here:
        String date = monthsDiagramsList.getSelectedValue().toString();
        Diagram diagram = new Diagram();
        String mode;

        if(diagramComboBox.getSelectedIndex() == 0) {
            mode = "expenses";
        } else {
            mode = "contributions";
        }

        diagram.createBarDiagram(date, db, mode);
    }//GEN-LAST:event_createBarDiagramActionPerformed

   
    private void createCircleDiagramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createCircleDiagramActionPerformed
        // TODO add your handling code here:
        String date = monthsDiagramsList.getSelectedValue().toString();
        Diagram diagram = new Diagram();
        String mode;
        Categories catDB = new Categories();
        if(diagramComboBox.getSelectedIndex() == 0) {
            mode = "expenses";
        } else {
            mode = "contributions";
        }

        diagram.createPieChart(date, db, catDB, mode);
    }//GEN-LAST:event_createCircleDiagramActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
        openDialog open = new openDialog(this.getFrame(), true);
        open.setLocation(512, 384);
        open.setVisible(true);
        //initComponents();
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        // TODO add your handling code here:
        choiceDialog choice = new choiceDialog((this.getFrame()), true);
        choice.setLocation(512, 384);
        choice.setVisible(true);
        //initComponents();
        
    }//GEN-LAST:event_jMenuItem2ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu categoryMenu;
    private javax.swing.JMenuItem checkReceiptToolItem;
    private javax.swing.JPanel comparisions;
    private javax.swing.JList contributionsList;
    private javax.swing.JPanel contributionsPanel;
    private javax.swing.JButton createBarDiagram;
    private javax.swing.JButton createCircleDiagram;
    private javax.swing.JButton deleteEntryButton;
    private javax.swing.JComboBox diagramComboBox;
    private javax.swing.JPanel diagrams;
    private javax.swing.JTabbedPane differentViews;
    private javax.swing.JMenuItem editCategoriesItem;
    private javax.swing.JMenuItem editShopsItem;
    private javax.swing.JTabbedPane expensesAndContributions;
    private javax.swing.JList expensesList;
    private javax.swing.JPanel expensesPanel;
    private javax.swing.JButton fromReceipt;
    private javax.swing.JButton fromScan;
    private javax.swing.JButton jButtonWyswietl;
    private javax.swing.JComboBox jComboBoxKategoria;
    private javax.swing.JComboBox jComboBoxProdukt;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JTable jTablePorownanie;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuItem manageProfilesToolItem;
    private javax.swing.JButton manualEntry;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JList monthsDiagramsList;
    private javax.swing.JList monthsList;
    private javax.swing.JMenuItem readReceiptItem;
    private javax.swing.JMenu receiptMenu;
    private javax.swing.JMenu receiptToolsMenu;
    private javax.swing.JPanel reports;
    private javax.swing.JMenu shopsMenu;
    private javax.swing.JButton showReportButton;
    private javax.swing.JPanel tabs;
    private javax.swing.JMenuItem trenningImagesToolItem;
    // End of variables declaration//GEN-END:variables
    private JDialog aboutBox;

  
   
}
